﻿

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>调休列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
    <link href="../../../layuiadmin/jquery-editable-select/jquery-editable-select.css" rel="stylesheet" />
    <script src="../../../layuiadmin/lib/jquery.min.js"></script>
    <script src="../../../layuiadmin/lib/api.js"></script>
    <script src="../../../layuiadmin/artdialog/artDialog.js?skins=chrome"></script>
    <script src="../../../layuiadmin/layui/layui.js"></script>
    <script src="../../../layuiadmin/lib/common.js"></script>
    <script src="../../../layuiadmin/lib/system.js"></script>
    <!--带输入和搜索的下拉框-->


    <script>
        //检查服务器是否已登录，没有登录则跳转至登录页。
        sys_islogin();
    </script>

</head>
<body>

    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                <div class="layui-form-item">

                    <div class="layui-inline">
                        <label class="layui-form-label">调休人</label>
                        <div class="layui-input-inline">
                            
                            <select id="realname" name="realname" class="layui-select" style="width:190px;" data-placeholder="请输入">
                            </select>
                        </div>
                    </div>
                    
                    <div class="layui-inline">
                        <label class="layui-form-label">选择日期</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" name="startTime" id="startTime" autocomplete="off" placeholder="开始日期">
                        </div>
                        <div class="layui-form-mid">
                            -
                        </div>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" name="endTime" id="endTime" autocomplete="off" placeholder="结束日期">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn layuiadmin-btn-list" id="LAY-app-contlist-search" lay-submit lay-filter="LAY-app-contlist-search">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                    </div>
                </div>
            </div>

            <div class="layui-card-body">
                <div style="padding-bottom: 10px;">
                    <button class="layui-btn layuiadmin-btn-list" data-type="batchdel">删除</button>
                    <button class="layui-btn layuiadmin-btn-list" data-type="add">添加</button>
                    
                </div>

                <table id="LAY-app-content-list" lay-filter="LAY-app-content-list"></table>

                <script type="text/html" id="table-content-list">
                    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
                </script>
            </div>
        </div>
    </div>

    <script src="../../../layuiadmin/jquery-editable-select/jquery-editable-select.js"></script>
    <script>
       
  layui.config({
    base: '../../../layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'contlist', 'table','laydate'], function(){
      var table = layui.table, form = layui.form;


    //监听搜索
    form.on('submit(LAY-app-contlist-search)', function(data){
        var field = data.field;
         
      //执行重载
      table.reload('LAY-app-content-list', {
        where: field
      });
    });


      //表格管理
      table.render({
          elem: '#LAY-app-content-list'
          , url: '/LeaveMerber/leaveList' //接口
          , cols: [[
              { type: 'checkbox', fixed: 'left',field: 'ID' }
              , { field: 'REALNAME', title: '调休人',align: 'center'}
              , { field: 'STARTTIME', title: '开始时间', align: 'center'}
              , { field: 'ENDTIME', title: '结束时间', align: 'center'}
              
              , { field: 'LEAVETIMES', title: '调休时长(小时)', sort: true, align: 'center' }
              , {
                  field: 'DETAIL', title: '备注', align: 'center'
              }
              
          //, { field: 'UPDATETIME', title: '修改时间', sort: true, align: 'center' }
          //, { field: 'CREATETIME', title: '添加时间', sort: true, align: 'center' }
          , { title: '操作', minWidth: 180, align: 'center', fixed: 'right', toolbar: '#table-content-list' }
          ]]
          , page: true
          , limit: 10
          , where: {

          }
          , limits: [10, 15, 20, 25, 30]
          , text: {
              none: '暂无相关数据'
          }
      });

      //监听表格的操作栏
      table.on('tool(LAY-app-content-list)', function (obj) {
          var data = obj.data;

          if (obj.event === 'del') {
              layer.confirm('确定删除此调休吗？', function (index) {

                  var isSucss = fun_del(data.ID);
                  if (isSucss>0) {
                      table.reload('LAY-app-content-list');
                      layer.msg('成功删除 ' + isSucss + " 数据");
                  }
                  layer.close(index);
              });
          } else if (obj.event === 'edit') {
              layer.open({
                  type: 2
                  , title: '编辑调休'
                  , content: 'leaveform.html'
                  , maxmin: true
                  , area: ['660px', '580px']
                  , success: function (layero, index) {
                      var iframe = window['layui-layer-iframe' + index];
                      // 向子页面的全局函数child_select_user传参
                      iframe.child_fill_data(data);
                  }

              });
          }
      });

    //表格上方的操作
    var $ = layui.$, active = {
        batchdel: function () {
            var checkStatus = table.checkStatus('LAY-app-content-list')
                , checkData = checkStatus.data; //得到选中的数据
            console.log(checkData);
            if (checkData.length === 0) {
                return layer.msg('请选择数据');
            }

            layer.confirm('确定删除调休吗？', function (index) {
                var ids = "";
                for (var i = 0; i < checkData.length; i++) {
                    ids += checkData[i].ID + ",";
                }
                var count = fun_del(ids);
                table.reload('LAY-app-content-list');
                layer.msg('成功删除 ' + count + " 数据");

        });
      },
      add: function(){
        layer.open({
          type: 2
          ,title: '添加调休'
          ,content: 'leaveform.html'
          ,maxmin: true
            , area: ['660px', '580px']

        });
      }
      };

      

    $('.layui-btn.layuiadmin-btn-list').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });

      //任务负责人搜索
      $("input[name=realname]").blur(function () {
          $("#LAY-app-contlist-search").click();
      });
     
      var laydate = layui.laydate;
      //开始日期
      var insStart = laydate.render({
          elem: '#startTime'
          //, min: 0
          //, type: 'datetime'
          , done: function (value, date) {
              //更新结束日期的最小日期
              insEnd.config.min = lay.extend({}, date, {
                  month: date.month - 1
              });

              //自动弹出结束日期的选择器
              insEnd.config.elem[0].focus();
          }
      });

      //结束日期
      var insEnd = laydate.render({
          elem: '#endTime'
          //, min: 0
          //, type: 'datetime'
          , done: function (value, date) {
              //更新开始日期的最大日期
              insStart.config.max = lay.extend({}, date, {
                  month: date.month - 1
              });
          }
      });

  });

      function fun_del(ids) {
          var isSucc = 0;
          $.ajax({
              url: "/LeaveMerber/DeleteLeave",    //请求的url地址
              dataType: "json",   //返回格式为json
              async: false,//请求是否异步，默认为异步，这也是ajax重要特性
              data: { delIds: ids },    //参数值
              type: "POST",   //请求方式
              beforeSend: function () {
                  //请求前的处理
              },
              success: function (data) {
                  //请求成功时处理
                  isSucc = data;
              },

              error: function (res) {
                  layer.msg("删除失败，请联系技术人员");
              }
          });
          return isSucc;
      };

      
      //任务负责人
      $.ajax({
          url: "/UserMerber/GetUserByDepartId",    //请求的url地址
          dataType: "json",   //返回格式为json
          //async: false,//请求是否异步，默认为异步，这也是ajax重要特性$("#attachCode").val()
          data: {},    //参数值
          type: "POST",   //请求方式
          success: function (res) {
              var html = "";
              for (var i = 0; i < res.length; i++) {
                  html += "<option value='" + res[i].ID + "'>" + res[i].REALNAME + "</option>";
              }

              $("#realname").html(html);
              $("#realname").editableSelect();
          },
          error: function (res) {
              console.log(res);
              //layer.msg("任务附件获取失败，请联系技术人员");
          }
      });
    </script>
</body>
</html>
